package com.chenglu.android.mine.collect.adapter;

import android.content.Context;
import android.os.Bundle;
import android.view.DragEvent;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import com.chenglu.android.R;
import com.chenglu.android.common.net.RetrofitClient;
import com.chenglu.android.common.utils.GlideUtils;
import com.chenglu.android.common.utils.Utils;
import com.chenglu.android.common.widget.SlideItemViewTest;
import com.chenglu.android.mine.bean.AmountTypeBean;
import com.chenglu.android.mine.bean.CollectBean;
import com.chenglu.android.redpacket.bean.PacketBean;
import com.yl.recyclerview.widget.SlideItemView;
import com.yl.recyclerview.wrapper.SwipeToDismissWrapper;

import java.util.List;

import io.reactivex.rxjava3.internal.schedulers.NewThreadWorker;

/**
 * @author: lyj
 * @Created: by Copyright 2023/7/24 Guangzhou Hongma Technology Co., Ltd. All rights reserved.
 * @Description：
 */
public class CollectAdapter extends BaseQuickAdapter<CollectBean.Data.Records, BaseViewHolder>  {

    private Context mContext;

//    private final ViewBinderHelper viewBinderHelper = new ViewBinderHelper();

    public CollectAdapter(Context context,int layoutResId, @Nullable List<CollectBean.Data.Records> data) {
        super(layoutResId, data);
        this.mContext = context;

    }

    @Override
    protected void convert(@NonNull BaseViewHolder helper, CollectBean.Data.Records item) {

        if(item == null){
            return;
        }
        //绑定侧滑id
//       SwipeRevealLayout swipeRevealLayout =  helper.getView(R.id.swipereveal_layout);
//       TextView tvDelete =  helper.getView(R.id.tv_delete);
//       helper.addOnClickListener(R.id.tv_delete);
//       viewBinderHelper.bind(swipeRevealLayout, item.getId());

        TextView tvPrice =  helper.getView(R.id.tv_item_price);
      TextView tvDistance =  helper.getView(R.id.tv_item_distance);
      RecyclerView recyclerView =  helper.getView(R.id.rv_item_coupon);

        SlideItemView slideItemView =  helper.getView(R.id.slideview);

//        if(item.isSlideView()) {
//            slideItemView.reset();
//        }else {
//
//        }

        //收藏类型 1-商品 2-店铺
        switch (item.getCollectType()){
            case 1:
                helper.setText(R.id.tv_item_title,item.getGoodsName());
                tvPrice.setVisibility(View.VISIBLE);
                tvPrice.setText("¥" + Utils.formatZeroNumber(item.getGoodsPrice()));
                tvDistance.setVisibility(View.GONE);
                recyclerView.setVisibility(View.GONE);
                break;
            case 2 :
                tvDistance.setVisibility(View.VISIBLE);
                tvPrice.setVisibility(View.GONE);
                helper.setText(R.id.tv_item_title,item.getShopsName());
                tvDistance .setText(item.getDistance()+"km");
                break;
        }
        ImageView imageView = helper.getView(R.id.iv_collect);
        GlideUtils.setImageView(mContext,item.getGoodsImg(),imageView,8);
        helper.setText(R.id.tv_item_sellnumber,"月售"+item.getMonthSaleCount());

        CouponListAdapter listAdapter = new CouponListAdapter(mContext,item.getCouponList());
        recyclerView.setLayoutManager(new LinearLayoutManager(mContext));
        recyclerView.setAdapter(listAdapter);
        listAdapter.notifyDataSetChanged();

        helper.addOnClickListener(R.id.tv_delete);
        helper.addOnClickListener(R.id.ll_slide);

    }

    //侧滑删除
//    public void saveStates(Bundle outState) {
//        viewBinderHelper.saveStates(outState);
//    }
//
//    public void restoreStates(Bundle inState) {
//        viewBinderHelper.restoreStates(inState);
//    }
}
